import pandas as pd
import pandas
import numpy as np
import openpyxl
        
def find_row(PN):
    # 读取excel文件
    data = pd.read_excel('./web_test_51case_8_28.xlsx')
    # 得到坐标
    coordinates = get_coordinates(data, PN)
    # 打印坐标
    print(coordinates)
    return coordinates[0]
      
      
def get_coordinates(data: pandas.DataFrame, target: str):
    """
    根据要查找的目标，返回其在excel中的位置
    data: excel数据,
    target: 要查找的目标
    return: 返回坐标列表
    """
    data_list = np.array(data).tolist()
    for i in range(len(data_list)):
        for j in range(len(data_list[i])):
            if data_list[i][j] == target:
                return [i + 1, j + 1]
    return []


def write2excel(row,result_list):
    
    wb = openpyxl.load_workbook('./web_test_51case_8_28.xlsx')
    print(wb.get_sheet_names())
    ws = wb[wb.sheetnames[0]]
    ws.cell(row+1, 13).value = result_list[0]
    ws.cell(row+1, 14).value = result_list[1]
    wb.save('./web_test_51case_8_28.xlsx')

